package engine.display.newAttack
{
	import engine.data.ResPath;
	import engine.display.newAttack.vo.FightInfoVo;
	import engine.display.newAttack.vo.FightPetInfoVo;
	import engine.flag.PlayerActionFlag;
	import engine.flag.ResourcesPath;
	import engine.tip.TipsMainLogic;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.loader.SwfLoader;

	public class AttackPet extends AttackPlayer
	{
		private var _pInfoUI : MovieClip;
		
		public var _movie	: MovieClip;
		
		private var _bufferCion :NxClip= new NxClip();
		
		private var _team	: int;
		
		override public function getSkin():MovieClip
		{
			// TODO Auto Generated method stub
			return _movie;
		}
		
		override public function reSetView():void
		{
			// TODO Auto Generated method stub
//			super.reSetView();
		}
		
		override public function resetHp(hp:int, maxhp:int):void
		{
			// TODO Auto Generated method stub
//			super.resetHp(hp, maxhp);
		}
		
		override public function resetMp(mp:int):void
		{
			// TODO Auto Generated method stub
//			super.resetMp(mp);
		}
		
		
		public var _fightInfoVo:FightPetInfoVo;
		
		private var _bufferPropertyArr:Array =[];
		
		public function AttackPet( team : int , pos :int)
		{
			super(pos);
			_bufferCion.source =  ResManager.newResClass("CustomControl_0009") ;
			_pInfoUI =  ResManager.newResClass("petbox") as MovieClip;//ResManager.getResContentCopy("petbox") as MovieClip;
//			_pInfoUI.y=50;
			if(_pInfoUI==null)return;
			_bufferCion.y =_bufferCion.x =20
			_pInfoUI.addChild(_bufferCion);
			addChild( _pInfoUI );
			
			mouseEnabled = mouseChildren = true;
			
			_pInfoUI.npcSpace.scaleX  =  team;
			
			x 	= uint(StaticIni.getIniVar("pet_" + team,"x"));
			y	= uint(StaticIni.getIniVar("pet_" + team,"y"));
			
			reset();
			
		}

		public function init( fightInfoVo:FightPetInfoVo ):void
		{
			_fightInfoVo = fightInfoVo;
			_bufferPropertyArr	 = 	[_fightInfoVo.petMaxHP,_fightInfoVo.petPhyDamage,_fightInfoVo.petPhyDef,_fightInfoVo.petMagDamage,_fightInfoVo.petMagDef,
									_fightInfoVo.petPhyDodgeProb,_fightInfoVo.petPhyHitProb,_fightInfoVo.petPhyWardProb,_fightInfoVo.petDePhyWardProb,
									_fightInfoVo.petPhyGuardProb,_fightInfoVo.petDePhyGuardProb,_fightInfoVo.petPhyVaProb,_fightInfoVo.petPhyVaDefProb];
			_pInfoUI.nameField.htmlText	=	fightInfoVo.petname ;
			SwfLoader.StartLoad( ResPath.ACTORS + "npc_" + fightInfoVo.petid + ".swf", null, onLoadResComplete, [ fightInfoVo.petid ] );
			this.buttonMode = true;
			addEventListener( MouseEvent.MOUSE_OVER, onOver );
			addEventListener( MouseEvent.MOUSE_OUT, onOut );
		}

		private function getTipsStr():String
		{
			var tipstr:String = "";
			tipstr += StaticIni.getSwfLangStr("UIString_1000600")+_fightInfoVo.petlevel+"\n";
			tipstr += StaticIni.getSwfLangStr("UIString_1000599")+_fightInfoVo.petgrade+"\n";
			var index:int = 0;
			for(var i:String in _bufferPropertyArr)
			{
				var vaule:String = String(_bufferPropertyArr[int(i)]) ;
				if(vaule != "0")
				{
					index++;
					if(index  == 3)
					{
						index  =1;
					}
					var strID:String = (1+int(i))>=10?"Pet_Property_":"Pet_Property_0"
					var str:String =StaticIni.getSwfLangStrVar(strID+String(1+int(i)), [vaule] );
					var isHave:Boolean=false;
					
					tipstr += StaticIni.getSwfLangStrVar(strID+String(1+int(i)), [vaule] ) ;
					if(index%2 !=0 )
					{
						tipstr += "\n";
					}
					else
					{
						if(str.indexOf("%")!=-1)
						{
							isHave = true;
						}
						tipstr +=initStr(vaule,isHave);
					}
				}
				
			}
			return tipstr;
		}	
		private function initStr(val:String,isHave:Boolean=false):String
		{
			var addlen:int = Math.abs(8-(val.toString().length));
			var str:String= "";
			for(var i:int=0; i<addlen;i++)
			{
				str += "&nbsp;";
			}
			if(!isHave)
			{
				str += "&nbsp;&nbsp;";
			}
			return str;
		}
		private function onOver( evt : MouseEvent ):void
		{
			var tipstr:String = "";
			tipstr =getTipsStr();
			TipsMainLogic.instance.showWideString(tipstr)	;
		}
		
		private function onOut( evt : MouseEvent ):void
		{
			TipsMainLogic.instance.hide();	
		}
		
		//npc加载完成
		private function onLoadResComplete( movie:DisplayObject,pList:Array ):void
		{
			_movie = movie as MovieClip;
			
			_pInfoUI.npcSpace.addChild( _movie );
			_pInfoUI.part2.gotoAndPlay(1);
			_movie.y=-10;
			_movie.scaleX = .6;
			_movie.scaleY = .6;
			_movie.gotoAndPlay( PlayerActionFlag.BigWait );
		}
		
	   override public function reset():void
		{
			if( null != _movie &&_movie.parent!=null)
			{
				_pInfoUI.npcSpace.removeChild( _movie );
				_fightInfoVo = null;
			}
			visible = false;
		}

	  override public function get team():int
		{
			return _team;
		}
	}
}